validate
目的 Purpose
Validates a domain class against the applied constraints (see Validation)詳細 Description
The validate
method validates a domain class based on its defined constraints. The errors are stored in the errors property of the domain class instance.The validate
method accepts an optional List
argument which contains the names of the properties to be validated. When a List
of names is specified, only those properties will be validated.使用例 Examples
def b = new Book(title: "The Shining") if (!b.validate()) { b.errors.each { println it } }
def a = new Album(artist: "Genesis", title: "Nursery Cryme", releaseDate: 1971)// only validate title and releaseDate if (!a.validate(["title", "releaseDate"])) { a.errors.each { println it } }
Parameters:
deepValidate
(optional) - Whether associations of the domain instance should also be validated, i.e. whether validation cascades. This istrue
by default; set it tofalse
to disable cascading validation.